\hypertarget{mac__15__4_8c}{
\section{/home/juha/ns\_\-1\_\-1\_\-0/subversion/nanostack/Common/modules/mac\_\-15\_\-4.c File Reference}
\label{mac__15__4_8c}\index{/home/juha/ns_1_1_0/subversion/nanostack/Common/modules/mac_15_4.c@{/home/juha/ns\_\-1\_\-1\_\-0/subversion/nanostack/Common/modules/mac\_\-15\_\-4.c}}
}
802.15.4 protocol module. 

{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}Free\-RTOS.h\char`\"{}}\par
{\tt \#include \char`\"{}task.h\char`\"{}}\par
{\tt \#include \char`\"{}queue.h\char`\"{}}\par
{\tt \#include \char`\"{}semphr.h\char`\"{}}\par
{\tt \#include \char`\"{}list.h\char`\"{}}\par
{\tt \#include \char`\"{}debug.h\char`\"{}}\par
{\tt \#include \char`\"{}socket.h\char`\"{}}\par
{\tt \#include \char`\"{}buffer.h\char`\"{}}\par
{\tt \#include \char`\"{}bus.h\char`\"{}}\par
{\tt \#include \char`\"{}module.h\char`\"{}}\par
{\tt \#include \char`\"{}control\_\-message.h\char`\"{}}\par
{\tt \#include \char`\"{}cipv6.h\char`\"{}}\par
{\tt \#include \char`\"{}rf.h\char`\"{}}\par
{\tt \#include \char`\"{}mac.h\char`\"{}}\par
{\tt \#include \char`\"{}gpio.h\char`\"{}}\par
{\tt \#include \char`\"{}aes.h\char`\"{}}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{mac__15__4_8c_e21043003731fcc05157f61cb6351a70}{FC\_\-DST\_\-MODE}~0x0C00
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{mac__15__4_8c_5ab9bd89f5668ce9096c7f90e2e7d6df}{mac\_\-task} (void $\ast$pv\-Parameters)
\item 
void \hyperlink{mac__15__4_8c_50c63df28d5eb2857387653e60c787c4}{push\_\-bl\_\-event} (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$b)
\item 
void \hyperlink{mac__15__4_8c_9d7b1129612d8ca2198198ae50bd97ab}{push\_\-ttl\_\-update\_\-event} (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$b)
\item 
void \hyperlink{mac__15__4_8c_e7ce2581092a30f23ebd8018f6fe7a8c}{mac\_\-data\_\-up} (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$buf)
\item 
mac\_\-tx\_\-status\_\-t \hyperlink{mac__15__4_8c_90f421f8a9616c7271345fc9d43a5bf0}{mac\_\-buffer\_\-out} (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$buf)
\item 
void \hyperlink{mac__15__4_8c_10fb5a7d3cd3ea7b7e5fa11098096e54}{mac\_\-adhoc} (mac\_\-event\_\-t event, \hyperlink{structbuffer__t}{buffer\_\-t} $\ast$buf)
\item 
void \hyperlink{mac__15__4_8c_075560080dee25cd872bfd7f6019cc4c}{mac\_\-scan} (mac\_\-event\_\-t curr\_\-event, \hyperlink{structbuffer__t}{buffer\_\-t} $\ast$buf)
\item 
uint8\_\-t \hyperlink{mac__15__4_8c_26123fe135eee072c63b8548f8ca402e}{mac\_\-header\_\-generate} (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$buf)
\item 
void \hyperlink{mac__15__4_8c_68176a1564f843a231850b1f23bec8a8}{mac\_\-timer\_\-callback} (void)
\item 
void \hyperlink{mac__15__4_8c_b2528ef2a5447d1130407d221baf9f80}{mac\_\-start\_\-ed\_\-scan} (void)
\item 
void \hyperlink{mac__15__4_8c_3a1aa8cd4d2b015130da2b84c52ec85f}{mac\_\-gw\_\-discover} (void)
\item 
void \hyperlink{mac__15__4_8c_9cd03f8f49180c7412f93beae31ae84c}{ack\_\-handle} (uint8\_\-t sqn)
\item 
void \hyperlink{mac__15__4_8c_758ebd59146e7c5d54243b4089cf0b51}{rf\_\-802\_\-15\_\-4\_\-ip\_\-layer\_\-address\_\-mode\_\-set} (uint8\_\-t support\_\-short\_\-addr)
\end{CompactItemize}


\subsection{Detailed Description}
802.15.4 protocol module. 

802.15.4 MAC and CSMA sequence: handler functions. Modular version for positioning support etc. 

\subsection{Define Documentation}
\hypertarget{mac__15__4_8c_e21043003731fcc05157f61cb6351a70}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!FC_DST_MODE@{FC\_\-DST\_\-MODE}}
\index{FC_DST_MODE@{FC\_\-DST\_\-MODE}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[FC\_\-DST\_\-MODE]{\setlength{\rightskip}{0pt plus 5cm}\#define FC\_\-DST\_\-MODE~0x0C00}}
\label{mac__15__4_8c_e21043003731fcc05157f61cb6351a70}


MAC Header masks 

\subsection{Function Documentation}
\hypertarget{mac__15__4_8c_9cd03f8f49180c7412f93beae31ae84c}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!ack_handle@{ack\_\-handle}}
\index{ack_handle@{ack\_\-handle}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[ack\_\-handle]{\setlength{\rightskip}{0pt plus 5cm}void ack\_\-handle (uint8\_\-t {\em sqn})}}
\label{mac__15__4_8c_9cd03f8f49180c7412f93beae31ae84c}


RF RX interrupt ACK handle.

Function check ACK status in the MAC.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em sqn}]ack sequency number \end{description}
\end{Desc}
\hypertarget{mac__15__4_8c_10fb5a7d3cd3ea7b7e5fa11098096e54}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_adhoc@{mac\_\-adhoc}}
\index{mac_adhoc@{mac\_\-adhoc}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-adhoc]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-adhoc (mac\_\-event\_\-t {\em curr\_\-event}, \hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em buf})}}
\label{mac__15__4_8c_10fb5a7d3cd3ea7b7e5fa11098096e54}


MAC ad-hoc mode packet handle. \hypertarget{mac__15__4_8c_90f421f8a9616c7271345fc9d43a5bf0}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_buffer_out@{mac\_\-buffer\_\-out}}
\index{mac_buffer_out@{mac\_\-buffer\_\-out}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-buffer\_\-out]{\setlength{\rightskip}{0pt plus 5cm}mac\_\-tx\_\-status\_\-t mac\_\-buffer\_\-out (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em buf})}}
\label{mac__15__4_8c_90f421f8a9616c7271345fc9d43a5bf0}


Buffer send API for MAC module.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em buf}]indicates pointer for buffer structure.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]MAC\_\-TX\_\-OK\_\-ACK, TX ok waiting ACK 

MAC\_\-TX\_\-OK TX complete 

MAC\_\-TX\_\-BUSY, channel busy 

MAC\_\-TX\_\-CCA, channel not free \end{Desc}
\hypertarget{mac__15__4_8c_e7ce2581092a30f23ebd8018f6fe7a8c}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_data_up@{mac\_\-data\_\-up}}
\index{mac_data_up@{mac\_\-data\_\-up}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-data\_\-up]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-data\_\-up (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em b})}}
\label{mac__15__4_8c_e7ce2581092a30f23ebd8018f6fe7a8c}


Push Data buffer to upper layer from MAC.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em buf}]indicates pointer for buffer structure. \end{description}
\end{Desc}
\hypertarget{mac__15__4_8c_3a1aa8cd4d2b015130da2b84c52ec85f}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_gw_discover@{mac\_\-gw\_\-discover}}
\index{mac_gw_discover@{mac\_\-gw\_\-discover}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-gw\_\-discover]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-gw\_\-discover (void)}}
\label{mac__15__4_8c_3a1aa8cd4d2b015130da2b84c52ec85f}


GW scan with channel change.

Change next channel and create \& send ROUTER SOLICATION MESSAGE \hypertarget{mac__15__4_8c_26123fe135eee072c63b8548f8ca402e}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_header_generate@{mac\_\-header\_\-generate}}
\index{mac_header_generate@{mac\_\-header\_\-generate}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-header\_\-generate]{\setlength{\rightskip}{0pt plus 5cm}uint8\_\-t mac\_\-header\_\-generate (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em buf})}}
\label{mac__15__4_8c_26123fe135eee072c63b8548f8ca402e}


Function creates MAC-frame.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em buf}]indicates pointer for buffer structure. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]ack flag which indicated ack-requirement for frame. \end{Desc}
\hypertarget{mac__15__4_8c_075560080dee25cd872bfd7f6019cc4c}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_scan@{mac\_\-scan}}
\index{mac_scan@{mac\_\-scan}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-scan]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-scan (mac\_\-event\_\-t {\em curr\_\-event}, \hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em buf})}}
\label{mac__15__4_8c_075560080dee25cd872bfd7f6019cc4c}


MAC scan mode function.

When MAC\_\-ENERGY\_\-SCAN is defined (GW device) this function analyze all 16 channel Energy level and select first free channel. \hypertarget{mac__15__4_8c_b2528ef2a5447d1130407d221baf9f80}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_start_ed_scan@{mac\_\-start\_\-ed\_\-scan}}
\index{mac_start_ed_scan@{mac\_\-start\_\-ed\_\-scan}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-start\_\-ed\_\-scan]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-start\_\-ed\_\-scan (void)}}
\label{mac__15__4_8c_b2528ef2a5447d1130407d221baf9f80}


Enable ED-scan.

Working only when MAC\_\-ENERGY\_\-SCAN defined \hypertarget{mac__15__4_8c_5ab9bd89f5668ce9096c7f90e2e7d6df}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_task@{mac\_\-task}}
\index{mac_task@{mac\_\-task}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-task]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-task (void $\ast$ {\em pv\-Parameters})}}
\label{mac__15__4_8c_5ab9bd89f5668ce9096c7f90e2e7d6df}


Mac task.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em pv\-Parameters}]not used \end{description}
\end{Desc}
\hypertarget{mac__15__4_8c_68176a1564f843a231850b1f23bec8a8}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!mac_timer_callback@{mac\_\-timer\_\-callback}}
\index{mac_timer_callback@{mac\_\-timer\_\-callback}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[mac\_\-timer\_\-callback]{\setlength{\rightskip}{0pt plus 5cm}void mac\_\-timer\_\-callback (void)}}
\label{mac__15__4_8c_68176a1564f843a231850b1f23bec8a8}


MAC timer Callback.

CB send MAC timer event to MAC \hypertarget{mac__15__4_8c_50c63df28d5eb2857387653e60c787c4}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!push_bl_event@{push\_\-bl\_\-event}}
\index{push_bl_event@{push\_\-bl\_\-event}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[push\_\-bl\_\-event]{\setlength{\rightskip}{0pt plus 5cm}void push\_\-bl\_\-event (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em b})}}
\label{mac__15__4_8c_50c63df28d5eb2857387653e60c787c4}


Push Broken Link event to c\-IPV module.

When ACK not received after 4 re-tx.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em buf}]indicates pointer for buffer structure. \end{description}
\end{Desc}
\hypertarget{mac__15__4_8c_9d7b1129612d8ca2198198ae50bd97ab}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!push_ttl_update_event@{push\_\-ttl\_\-update\_\-event}}
\index{push_ttl_update_event@{push\_\-ttl\_\-update\_\-event}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[push\_\-ttl\_\-update\_\-event]{\setlength{\rightskip}{0pt plus 5cm}void push\_\-ttl\_\-update\_\-event (\hyperlink{structbuffer__t}{buffer\_\-t} $\ast$ {\em b})}}
\label{mac__15__4_8c_9d7b1129612d8ca2198198ae50bd97ab}


Push Neighbour \& Routing table TTL update event to c\-IPV module.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em buf}]indicates pointer for buffer structure. \end{description}
\end{Desc}
\hypertarget{mac__15__4_8c_758ebd59146e7c5d54243b4089cf0b51}{
\index{mac_15_4.c@{mac\_\-15\_\-4.c}!rf_802_15_4_ip_layer_address_mode_set@{rf\_\-802\_\-15\_\-4\_\-ip\_\-layer\_\-address\_\-mode\_\-set}}
\index{rf_802_15_4_ip_layer_address_mode_set@{rf\_\-802\_\-15\_\-4\_\-ip\_\-layer\_\-address\_\-mode\_\-set}!mac_15_4.c@{mac\_\-15\_\-4.c}}
\subsubsection[rf\_\-802\_\-15\_\-4\_\-ip\_\-layer\_\-address\_\-mode\_\-set]{\setlength{\rightskip}{0pt plus 5cm}void rf\_\-802\_\-15\_\-4\_\-ip\_\-layer\_\-address\_\-mode\_\-set (uint8\_\-t {\em support\_\-short\_\-addr})}}
\label{mac__15__4_8c_758ebd59146e7c5d54243b4089cf0b51}


Function setup IP modules address mode and also forward MAC and short address information.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em support\_\-short\_\-addr}]1=Support \& 0=Not support. \end{description}
\end{Desc}
